dojo.declare("MCustomerOrderSelectPgBkUp", wm.Page, {

    start: function() {

    },
    "preferredDevice": "phone",

    isNumber: function(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    },
    selectOrderItem: function(selItemId, itemRowNum) {

        var itemExist = false;
        var data = this.vOrderedItems.getData();

        for (var i = 0; i < data.length; i++) {
            var itemSel = data[i].itemId;
            if (itemSel === selItemId) {
                itemExist = true;
                this.vOrderedItems.removeItem(i);
            }

        }

        if (!itemExist) {

            var rowData = this.listVendorItems.getItemData(itemRowNum);

            var price = (1 * rowData.price);

            this.vOrderedItems.addItem({
                itemId: selItemId,
                itemName: rowData.itemName,
                quantity: 1,
                orderedPrice: price,
                desc: rowData.itemDesc
            });

        }

        //
    },

    selectItemQuantity: function(selItemId, selIndex) {


        var data = this.vOrderedItems.getData();
        var newItemName = '';
        var newDesc = '';
        var newItemPrice = 1;
        var qty = selIndex + 1;
        var price = 1;
        for (var i = 0; i < data.length; i++) {
            var itemSel = data[i].itemId;
            if (itemSel === selItemId) {
                newItemName = data[i].itemName;
                newDesc = data[i].desc;

                newItemPrice = data[i].orderedPrice;
                price = (qty * data[i].orderedPrice);

                this.vOrderedItems.removeItem(i);
            }

        }


        this.vOrderedItems.addItem({
            itemId: selItemId,
            itemName: newItemName,
            quantity: qty,
            orderedPrice: price,
            desc: newDesc
        });

    },

    listVendorItemsItemNameFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        // var items = '<div class="MobileRow" style="font-size:12px">Quantity </div> <div class="MobileRow"> <select name="Quantity" onchange="main.pcCustomerContent.page.pcItemList.page.selectItemQuantity(' + rowObj.itemId + ',this.selectedIndex);"> ' + '<option value="1">1</option>' + '<option value="2">2</option>' + '<option value="3">3</option>' + '<option value="4">4</option>' + '<option value="5">5</option>' + '<option value="6">6</option>' + '<option value="7">7</option>' +
        //
        // '</select> </div>';
        var display = "<div class='MobileRow' style='font-size:13px'><b>" + rowObj.itemName + "</b></div>" + "<div class='MobileRow'> </div>" + "<div class='MobileRow'>Price: " + rowObj.price + "</div>";

        return display;
    },
    listVendorItemsItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var selItemName = rowObj.itemName;
        //alert(selItemName);
        //    return '<INPUT TYPE=CHECKBOX NAME="defaultView" CHECKED onchange=main.pcContent.page.pcDashboard.page.pdlgViewPreferenceOptions.page.pdManagePreference.page.setDefaultUserPreference(' + inValue + ',' + rowId + ')><P>';
        //var chkBoxStr = '<div class="MobileRow">Order</div>' + ' <INPUT TYPE="CHECKBOX" NAME=chk' + inValue + '" id="chk' + inValue + '" onchange="main.pcCustomerContent.page.pcItemList.page.selectOrderItem('+rowId+ ',' + inValue + ');" ></input>';
        var chkBoxStr = '<div class="MobileRow" style="font-size:13px">Order</div> <div class="MobileRow" style="font-size:13px"> <INPUT TYPE=CHECKBOX height="20px" NAME="defaultView" onchange=mobileMainPg.pcContent.page.pcItemList.page.selectOrderItem(' + inValue + ',' + rowId + ') > </div>';

        return chkBoxStr;
    },
    listVendorItemsQuantityFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        var items = '<div class="MobileRow" style="font-size:12px">Qty </div> <div class="MobileRow"> <select name="Quantity" onchange="mobileMainPg.pcContent.page.pcItemList.page.selectItemQuantity(' + rowObj.itemId + ',this.selectedIndex);"> ' + '<option value="1">1</option>' + '<option value="2">2</option>' + '<option value="3">3</option>' + '<option value="4">4</option>' + '<option value="5">5</option>' + '<option value="6">6</option>' + '<option value="7">7</option>' +

        '</select> </div>';
        return items;
    },
    listVendorItemsItemDescFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        var commentBox = "<div class='MobileRow'>Comment:</div>" + "<input type='text' name='comment'/>";

        return commentBox;
    },

    list1ItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var display = "<div class='MobileRowTitle'>Item Name: " + rowObj.desc + "</div>" + "<div class='MobileRow'>Quantity: " + rowObj.quantity + "</div>" + "<div class='MobileRow'>OrderedPrice: " + rowObj.orderedPrice + "</div>";


        return display;
    },
    svPlaceOrderSuccess: function(inSender, inDeprecated) {

    },
    listVendorItemsImageUrlFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        try {
            var file = "services/FileUploadDownload.download?method=downloadFile&fileName=" + inValue;
            return '<img  style="height: 60px;width: 60px;" src="' + file + '" />';
        } catch (e) {
            console.error('ERROR IN dojoGrid2PicurlFormat: ' + e);
        }
    },

    listFinalOrderItemNameFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var display = "<div class='MobileRowTitle'>Item Name: " + rowObj.itemName + "</div>" + "<div class='MobileRowTitle'>Item Desc: " + rowObj.desc + "</div>" + "<div class='MobileRow'>Quantity: " + rowObj.quantity + "</div>" + "<div class='MobileRow'>OrderedPrice: " + rowObj.orderedPrice + "</div>";
        return display;
    },
    svCompleteOrderSuccess1: function(inSender, inDeprecated) {
        //alert(inSender.data.dataValue);
        this.vOrderedItems.clearData();
        wm.Page.getPage("DCustomerHomePg").ncServices.update();
        wm.Page.getPage("DCustomerHomePg").panelOrderResultDisplay.setShowing(true);
        wm.Page.getPage("DCustomerHomePg").labelOrderResult.setCaption(inSender.data.dataValue);



    },
    listVendorItemsPriceFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var display = "<div class='MobileRow' style='font-size:13px'><font color='red'>Price </font></div>  <div class='MobileRow' style='font-size:13px'><b> <font color='red'>" + rowObj.price + " Rs</font></b></div>";

        return display;

    },
    button4Click: function(inSender) {

        //wm.Page.getPage("")
        var mainPage = wm.Page.getPage("MobileMainPg");

        this.svCompleteOrder.input.setValue("order.customerId", mainPage.vUserId);

        this.svCompleteOrder.update();
    },
    _end: 0
});